function appointment_add(obj) {//点击新建跳转页面-新建预约
    window.location.href = Feng.ctxPath + "/receptionPatientsCentral/appointment_add";
}

function switcherDoctor() {//变换医生更新预约视图
    $('#calendar').fullCalendar('refetchEvents');
}

function getDate(time) {//获取周时间
    $(".days").html("");
    var date = time;
    var currentYear = date.getFullYear();
    var currentMonth = (date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var currentDay = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    var currentWeek = date.getDay() === 0 ? 7 : date.getDay();
    var str = currentYear + "-" + currentMonth + "-" + currentDay;
    $(".patient-navigation-title").html(str);

    var days = [], li = '';

    for (var i = currentWeek - 1; i >= 0; i -= 1) {
        var d = new Date(str);
        d.setDate(d.getDate() - i);
        days.push(d)
    }
    for (var w = 1; w <= 7 - currentWeek; w += 1) {
        var s = new Date(str);
        s.setDate(s.getDate() + w);
        days.push(s)
    }
    for (var e = 0; e < days.length; e++) {
        var time2 = setDateTime(days[e], 0);
        if (date.getDate() == days[e].getDate()) {
            li = '<li value="' + time2 + '" style="color: red">' + days[e].getDate() + '</li>';
        } else {
            li = '<li value="' + time2 + '">' + days[e].getDate() + '</li>';
        }
        $(".days").append(li);
    }

}

$(function () {
    $(".home-tabBar > .home-tabBar-item").eq(1).click();
    getDate(new Date());
});

$('#calendar').fullCalendar({
    header: {
        left: '',
        center: '',
        right: ''
    },
    defaultView: 'agendaDay',
    allDaySlot: false,
    navLinks: true,
    selectable: true,
    selectHelper: true,
    editable: true,
    eventLimit: true,
    handleWindowResize: true,
    nowIndicator: true,
    minTime: "07:00:00",
    maxTime: "20:00:00",
    slotDuration: "00:30:00",
    selectMinDistance: 30,
    timeFormat: 'H:mm',
    slotEventOverlap: false,
    schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
    dragRevertDuration: 200,
    unselectAuto: false,
    groupByResource: false,
    height: window.innerHeight - 90,
    slotLabelFormat: 'HH:mm',
    slotLabelInterval: "00:30:00",
    events: function (start, end, timezone, callback) {
        $.ajax({
            url: Feng.ctxPath + '/receptionPatientsCentral/getDataListApp',
            dataType: 'json',
            type: 'POST',
            data: {
                doctor: $("#doctor").val(),
                timeValue: start.format('YYYY-MM-DD')
            },
            success: function (data) {
                var events = [];
                $.each(data, function (key, value) {
                    var obj = {
                        id: value.customerId,
                        title: value.doctor,
                        start: new Date(Date.parse(value.startTime)),
                        end: new Date(Date.parse(value.endTime)),
                        customerName: value.customerName,
                        resourceId: value.id,
                        remarksReservation: value.remarksReservation,
                        customerStatus: value.customerStatus,
                        reservationsId: value.reservationsId,
                        checkStatus: value.checkStatus,
                        backgroundColor: "#2DC87E",
                        borderColor: "white"
                    };
                    events.push(obj)
                });
                callback(events)
            }
        })
    },
    eventAfterRender: function (calEvent, element, view) {
        element.prepend("<div class='myfc-title'><span style='font-size: 14px;letter-spacing: 2px;'>" + calEvent.customerName + "</span></div><div style='position: absolute;right: 2px;top: 2px;color: white;background: red;padding: 0 2px;border: 1px solid white;border-radius: 5px;font-size: 0.5em'>" + calEvent.customerStatus + "</div>")
    }
});

$(".home-tabBar > .home-tabBar-item").click(function () {
    if (!$(this).find('div').hasClass('home-tabBar-text')) {
        $(this).find('div').addClass('home-tabBar-text');
        $(this).siblings().find('div').removeClass('home-tabBar-text');
        $(this).find('.selection').show().siblings('.unchecked').hide();
        $(this).siblings().find('.unchecked').show().siblings('.selection').hide();
        if ($(this).find('div').html() == "首页") {
            window.location.href = Feng.ctxPath + "/weixin/index";
        } else if ($(this).find('div').html() == "我的") {
            window.location.href = Feng.ctxPath + "/appMy/my";
        }
    }
});

$(".patient-navigation-title").click(function () {
    laydate({
        istime: true,
        format: 'YYYY-MM-DD',
        choose: function (value) {
            getDate(new Date(value));
            $('#calendar').fullCalendar('gotoDate', value);
        }
    })
});

$(".days").on('click', 'li', function () {
    var time = $(this).attr('value');
    $(this).css({'color': 'red'}).siblings().css({'color': 'white'});
    $(".patient-navigation-title").html(time);
    $('#calendar').fullCalendar('gotoDate', time);
});